home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / cache.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.5 KB  |  105 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: cache.h
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer   
  8. // File Creation Date: 02/07/1997  
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The Cache class is derived from the Cacheb class. It adds two
  32. functions to handle the allocation and de-allocation of buckets.
  33. The cache is used to handle requests for file-based objects. The
  34. cache must determine whether an object is already loaded. If the
  35. object is not loaded the cache reserves a bucket and loads the
  36. object into memory. This cache design uses cache pointers to
  37. reference cache buckets directly, with each cache pointer being
  38. initialized after the bucket is reserved. The least-recently
  39. reserved cache bucket is overwritten when the cache fills up.
  40. */
  41. // ----------------------------------------------------------- //   
  42. #ifndef __CACHE_HPP__
  43. #define __CACHE_HPP__
  44.  
  45. #include "bucket.h"
  46.  
  47. // NOTE: To avoid portability problems with template classes, enable
  48. // the __NOT_USING_TEMPLATE_CLASS__ macro and directly code the
  49. // Bucket class, Cache class, and the CachePtr class for the data
  50. // type that will be used.
  51.  
  52. // Default to using template class
  53. #ifndef __NOT_USING_TEMPLATE_CLASS__
  54. #define __USING_TEMPLATE_CLASS__
  55. #endif
  56.  
  57. #ifdef __USING_TEMPLATE_CLASS__
  58. // Cache class
  59. template<class TYPE>
  60. class Cache : public Cacheb
  61. {
  62. public:
  63.   Cache(int n);
  64.   virtual ~Cache();
  65.  
  66. protected:
  67.   Bucket<TYPE> *buckets;
  68. };
  69.  
  70. template<class TYPE>
  71. Cache<TYPE>::
  72. Cache(int n) : Cacheb(buckets = new Bucket<TYPE>[n], n, sizeof(Bucket<TYPE>))
  73. // Buckets are stored in an array and organized as a circular doubly-linked
  74. // list by the Cacheb class.
  75. {
  76.  
  77. }
  78.  
  79. template<class TYPE>
  80. Cache<TYPE>::~Cache()
  81. {
  82.   if (fptr) Flush(); Disconnect();
  83.   delete[] buckets;
  84. }
  85. #endif // __USING_TEMPLATE_CLASS__
  86.  
  87. #ifdef __NOT_USING_TEMPLATE_CLASS__
  88. // (C)ache class
  89. class Cache : public Cacheb
  90. {
  91. public:
  92.   Cache(int n);
  93.   virtual ~Cache();
  94.  
  95. protected:
  96.   Bucket *buckets;
  97. };
  98. #endif //  __NOT_USING_TEMPLATE_CLASS__
  99.  
  100. #endif // __CACHE_HPP__
  101. // ----------------------------------------------------------- // 
  102. // ------------------------------- //
  103. // --------- End of File --------- //
  104. // ------------------------------- //
  105.